package jcu.sal.agent;

import java.io.IOException;

import jcu.sal.common.exceptions.ConfigurationException;


/**
 *
 * @author Marc Hammerton
 *
 */

public class SALAgentStart {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length < 3 ) {
			System.out.println("We need at least three arguments:");
			System.out.println("1: the connection method - 2: the platform configuration file - 3: the sensor configuration file - 4+: Connection specific (e.g. the IP address of rmi registry)");
			System.exit(1);
		}
		
		SALAgentInitI agent = null;

		if (args[0].equals("RMI")) {
			agent = new RMIAgentImpl(args[3]);
		} else if (args[0].equals("NETTY")) {
			agent = new NettyAgentImpl();
		}
				
		try {
			agent.start(args[1], args[2]);
		} catch (ConfigurationException e1) {
			e1.printStackTrace();
		}
		
		System.out.println(args[0] + " SAL Agent ready. Press <Enter> to quit");
		try {
			System.in.read();
		} catch (IOException e) {
			e.printStackTrace();
		}

		agent.stop();
		System.exit(0);
	}

}
